package com.yixun.qfbao.hander;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.EstateAdviserService;
import com.yixun.qfbao.apidto.EstateAdviserDto;
import com.yixun.qfbao.apidto.ListEstateAdviserByPremisesIdResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.ListEstateAdviserByPremisesIdReqVo;
import com.yixun.qfbao.vo.Listv10EstateAdviserByPremisesIdReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

@Service
public class ListEstateAdviserByPremisesIdHandler extends CommonAbstractHander {

	private static Logger logger = LoggerFactory.getLogger(ListEstateAdviserByPremisesIdHandler.class);

	@Autowired
	private EstateAdviserService estateAdviserService;

	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {

		BaseResponseDTO<List<EstateAdviserDto>> res = new BaseResponseDTO<>();

		ListEstateAdviserByPremisesIdResDto resDto = new ListEstateAdviserByPremisesIdResDto();

		if (reqDto instanceof ListEstateAdviserByPremisesIdReqVo) {
			/*
			 * 处理巧渠道
			 */
			ListEstateAdviserByPremisesIdReqVo req = (ListEstateAdviserByPremisesIdReqVo) reqDto;

			try {

				resDto = estateAdviserService.listEstateAdviserByPremisesId(req.getParams());

			} catch (Exception e) {
				logger.error("list estate adviser by premisesId error: {}", e);
				resDto.setResult(ResultEnum.FAIL.getNo());
				resDto.setResultMsg("根据楼盘id获取楼盘置业顾问错误！");
			}


		} else if (reqDto instanceof Listv10EstateAdviserByPremisesIdReqVo) {
			/*
			 * 处理v10
			 */
			Listv10EstateAdviserByPremisesIdReqVo req = (Listv10EstateAdviserByPremisesIdReqVo) reqDto;

			try {

				resDto = estateAdviserService.listEstateAdviserByPremisesId(req.getParams());

			} catch (Exception e) {

				logger.error("list estate adviser by premisesId error: {}", e);

				resDto.setResult(ResultEnum.FAIL.getNo());

				resDto.setResultMsg("根据楼盘id获取楼盘置业顾问错误！");
			}

		}
		
		res.setResData(resDto.getList());
		
		res.setResult(resDto.getResult());

		return res;

	}

}
